package cn.ren.cloud.controller;

import cn.ren.cloud.doc.EsCourseDoc;
import cn.ren.cloud.dto.CourseSearchDto;
import cn.ren.cloud.result.JsonResult;
import cn.ren.cloud.result.PageList;
import cn.ren.cloud.service.IEsCourseService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 23508
 */
@RestController
@RequestMapping("/courseEs")
public class EsCourseController {

    private final IEsCourseService esCourseService;

    public EsCourseController(IEsCourseService esCourseService) {
        this.esCourseService = esCourseService;
    }

    /**
     * 保存ES
     *
     * @param courseEs
     * @return
     */
    @PostMapping("/saveCourseEs")
    public JsonResult saveCourseEs(@RequestBody EsCourseDoc courseEs) {
        esCourseService.save(courseEs);
        return JsonResult.success();
    }

    /**
     * 前端获取数据
     *
     * @param doc
     * @return
     */
    @PostMapping("/search")
    public JsonResult search(@RequestBody CourseSearchDto doc) {
        PageList<EsCourseDoc> pageList = esCourseService.search(doc);
        return JsonResult.success(pageList);
    }

}


